﻿using System;
using System.Collections.Generic;
using KMF.Common;

namespace KMF.DAL
{
    public partial class ProductCategoryDb
    {

        public static List<ProductCategoryByPromotionPageDto> GetAllByPromotionPage()
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSP_ProductCategory_GetAllByPromotion");
            try
            {
                var result = dao.GetDTOList<ProductCategoryByPromotionPageDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }

        }//End method


        public static List<ProductCategoryParentCateDto> GetCategoryByParent(string categoryId)
        {

            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductCategory_GetParentById");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@CategoryID", categoryId));
                var result = dao.GetDTOList<ProductCategoryParentCateDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }

        public static List<ProductCategoryOnHomeDto> GetItemOnHome()
        {

            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductCategory_GetItemOnHome");
            try
            {
                var result = dao.GetDTOList<ProductCategoryOnHomeDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }
        public static List<ProductCategoryMenuLeftDto> GetMenuLeftOnCategoryHome()
        {

            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductCategory_GetMenuLeft");
            try
            {
                var result = dao.GetDTOList<ProductCategoryMenuLeftDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }
        public static List<ProductChildCateDto> GetChildCate(string cate)
        {

            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductCategory_GetChildCate");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@Cate", cate));
                var result = dao.GetDTOList<ProductChildCateDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }
        //public static List<ProductCategoryByNameDto> GetParentCateFromGoldenTime()
        //{
        //    var listCate = GetListCateFromGoldenTime();
        //    var strlistCate = "";
        //    if (listCate.Count > 0)
        //    {
        //        var count = 0;
        //        foreach (var item in listCate)
        //        {
        //            var parent = item.BreadCrumb.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries)[0];
        //            count++;
        //            var str = "',";
        //            if (count == listCate.Count)
        //                str = "'";
        //            strlistCate += "'" + parent + str;
        //        }
        //    }

        //    var dao = SharedSqlDao;
        //    var command = dao.GetDbSQLCommand("SELECT Name FROM ProductCategory WHERE Id in (" + strlistCate + ") ORDER BY Ordering");
        //    try
        //    {
        //        var result = dao.GetDTOList<ProductCategoryByNameDto>(ref command);
        //        return result;
        //    }
        //    finally
        //    {
        //        command.Connection.Close();

        //    }
        //}
    }
}
